<?php
/***
 * 描述：角色管理模块
 * @category		
 * @package		Lib			
 * @subpackage	Action.System	
 * @author		wanght <whtaok@gmail.com>
 * @since		2013-4-6
 * @version		$Id: RoleAction.class.php 3 2013-10-14 02:49:41Z whtaok@gmail.com $
 */
class RoleAction extends SystemAction {
	/**
	 * 描述：初始化角色模块
	 * @access		protected
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	protected  function _initialize() {
		parent::_initialize();
		$this->usingModel="ShopUserRole";
	}
	
	/**
	 * 描述：显示角色查询页面
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-4-6
	 */
	public function indexAct() {
		$mod = new ShopUserRoleModel();
		$search = array();
		if(I('title')){
			$search['title'] = I('title');
		}
		
		$list = $mod->where($search)->select();
		$this->assign("list",$list);
		$this->assign("search",$search);
		$this->display('index');
	}
	
	/**
	 * 描述：显示添加角色页面
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-4-6
	 */
	public function showAddAct() {
		exit($this->fetch("add"));
	}
	
	/**
	 * 描述：添加角色
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-4-6
	 */
	public function doAddAct() {
		$mod = new ShopUserRoleModel();
		if(!$mod->create()){
			$this->error($mod->getError());
		}		
		$mod->add();
		$this->success('添加成功', U('index'));
		
	}
	
	/**
	 * 描述：显示更新角色页面
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-4-6
	 */
	public function showUpdAct($id) {
		$mod = new ShopUserRoleModel();
		$role = $mod->find($id);
		$this->assign("detail",$role);
		exit($this->fetch("upd"));
	}
	
	/**
	 * 描述：更新角色
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-4-6
	 */
	public function doUpdAct($id) {
		$mod = new ShopUserRoleModel();
		if(!$mod->create()){
			$this->error($mod->getError());
		}
		$mod->save();
		$this->success('保存成功', U('index'));
	}
	
	public function doDelAct(){
		$id_list = array_values($this->_param('id'));
		if($id_list){
			$mod = new ShopUserRoleModel();
			$data['id'] = array('in',$id_list);
			$mod->where($data)->delete();
		}
		$this->success('删除成功', U('index'));
	}
}

?>